import { defineStore } from "pinia";
// 创建store,命名规则： useXxxxStore
// 参数1：store的唯一 id
// 参数2：对象，可以提供state actions getters
const useCounterStore = defineStore("counter", {
  // 等同于 data
  state: () => ({
    count: 10,
  }),
  // 等同于 computed
  getters: {
    double() {
      return this.count * 2;
    },
  },

  // 等同于 methods
  actions: {
    add() {
      this.count++;
    },
    addAsync() {
      setTimeout(() => {
        this.count++;
      }, 2000);
    },
  },
});

export default useCounterStore;
